package cur.nature.admin.service;

import cur.nature.admin.dao.Admin_DeptDao;
import cur.nature.framework.mvc.crud.CrudService;
import cur.nature.admin.model.vo.Admin_DeptVO;
import cur.nature.admin.model.po.Admin_DeptPO;
import cur.nature.framework.mvc.tree.TreeNode;
import cur.nature.framework.core.util.ObjectUtil;
import cur.nature.framework.mvc.tree.TreeUtil;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 用户角色 Service
 * 作者：Auto Generator By wujian
 * 生成日期：2023-07-10 21:42:14
 */
@Service
public class Admin_DeptService extends CrudService<Admin_DeptPO, Admin_DeptVO, Admin_DeptDao> {
    public Admin_DeptService(Admin_DeptDao baseDao) {
        super(baseDao, Admin_DeptPO.class, Admin_DeptVO.class);
    }

    public Admin_DeptVO.list_Result list(Admin_DeptVO.list_Param param) throws Exception {
        Admin_DeptVO.list_Result result = new Admin_DeptVO.list_Result();
        TreeNode topNode = new TreeNode("0", param.getNodeText());
        result.setTreeNode(topNode);
        // 查询出所有的资源
        List<Admin_DeptVO> list = getDao().queryByCond(param);
        if(ObjectUtil.isNotEmpty(list)){
            //转换为树节点
            List<TreeNode> treeNodeList = list.stream().map(base -> new TreeNode(base.getId()+"",base.getParentId(),base.getName(),base))
                    .collect(Collectors.toList());
            //组装树
            TreeUtil.packTree(treeNodeList, topNode);
        }
        return result;
    }

}

